<?php

namespace app\admin\controller;

use app\common\controller\Backend;
use think\Config;

/**
 * 控制台
 *
 * @icon fa fa-dashboard
 * @remark 用于展示当前系统中的统计数据、统计报表及重要实时数据
 */
class Dashboard extends Backend
{

    /**
     * 查看
     */
    public function index()
    {
        $seventtime = \fast\Date::unixtime('day', -7);
        $paylist = $createlist = [];
        for ($i = 0; $i < 7; $i++)
        {
            $day = date("Y-m-d", $seventtime + ($i * 86400));
            $createlist[$day] = mt_rand(20, 200);
            $paylist[$day] = mt_rand(1, mt_rand(1, $createlist[$day]));
        }
        $hooks = config('addons.hooks');
        $uploadmode = isset($hooks['upload_config_init']) && $hooks['upload_config_init'] ? implode(',', $hooks['upload_config_init']) : 'local';
        $addonComposerCfg = ROOT_PATH . '/vendor/karsonzhang/fastadmin-addons/composer.json';
        Config::parse($addonComposerCfg, "json", "composer");
        $config = Config::get("composer");
        $addonVersion = isset($config['version']) ? $config['version'] : __('Unknown');



        //获取平台总收入
        $ping_price = db('gzns_order')->where('order_status!=0')->where('order_status!=3')->sum('actual_price');
        //获取平台用户数
        $ping_user_count = db('gzns_user_info')->count();
        //获取平台会员数
        $ping_user_vip_count = db('gzns_user_vip_level')->count();
//        //获取平台个人会员数
//        $ping_geren_vip_count = db('gzns_user_vip_level uvl')
//            ->join('gzns_vip_level vl','uvl.vip_level_id = vl.id','left')
//            ->where('vl.vip_type',1)
//            ->count();
//        //获取平台单位会员数
//        $ping_danwei_vip_count = db('gzns_user_vip_level uvl')
//            ->join('gzns_vip_level vl','uvl.vip_level_id = vl.id','left')
//            ->where('vl.vip_type',2)
//            ->count();
        //获取平台待审核会员数
        $ping_shenhe_vip_count = db('gzns_user_vip_apply')->where('status', 1)->count();

        $today = date('Y-d-m');
        //获取今日新增用户数
        $today_user_count = db('gzns_user_info')->where('create_time', 'like', $today . '%')->count();
//        //获取今日新增会员数
//        $today_user_vip_count = db('gzns_user_vip_apply')->where('status', 2)->where('create_time', 'like', $today . '%')->count();
        //获取今日新增收入
//        $today_price = db('gzns_order')->where('order_status!=0')->where('order_status!=3')->where('create_time', 'like', $today . '%')->sum('actual_price');
        $wait_activity_count = db('gzns_order')
          ->where('order_status', 1)
          ->where('order_type', 2)
          ->where('create_time', 'like', $today . '%')->count();

      $wait_goods_count = db('gzns_order')
        ->where('order_status', 1)
        ->where('order_type', 3)
        ->where('create_time', 'like', $today . '%')->count();


        $this->view->assign([
            'ping_price'        => $ping_price,
            'ping_user_count'        => $ping_user_count,
            'ping_user_vip_count'        => $ping_user_vip_count,
            'wait_activity_count'        => $wait_activity_count,
            'wait_goods_count'        => $wait_goods_count,
//            'ping_geren_vip_count'        => $ping_geren_vip_count,
//            'ping_danwei_vip_count'        => $ping_danwei_vip_count,
            'ping_shenhe_vip_count'        => $ping_shenhe_vip_count,
            'today_user_count'        => $today_user_count,
//            'today_price'        => $today_price,

            'totaluser'        => 35200,
            'totalviews'       => 219390,
            'totalorder'       => 32143,
            'totalorderamount' => 174800,
            'todayuserlogin'   => 321,
            'todayusersignup'  => 430,
            'todayorder'       => 2324,
            'unsettleorder'    => 132,
            'sevendnu'         => '80%',
            'sevendau'         => '32%',
            'paylist'          => $paylist,
            'createlist'       => $createlist,
            'addonversion'       => $addonVersion,
            'uploadmode'       => $uploadmode
        ]);

        return $this->view->fetch();
    }

}
